<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>index</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../../css/mui.min.css">
		<link rel="stylesheet" href="./css/common.css">
		<style>
			html,
			body {
				background-color: #efeff4;
			}
			
			.home_icon {
				width: 20px;
			}
			
			.mui-bar-tab .mui-tab-item.mui-active {
				color: #0082E6;
			}
			
			.mui-bar-tab {
				height: 53px;
				padding-top: 3px;
			}
      .footer{
        position: fixed;
        width: 100%;
        z-index: 9999;
       height: 53px;
       
        line-height: 53px;
        background-color: #fff;
        bottom: 0;
        padding: 0;
        padding-top: 3px;
        text-align: center;
      }
		</style>
	</head>

	<body>
		
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">一机一档</h1>
		</header>
    <div class="footer flex shadow" v-if="editShow" id="home">
      <div class="flex-sub" @click="chooseAll">{{all?"取消全选":"全选"}}</div>
      <div class="flex-sub bg-red text-white" @click="offline()">
        离线缓存
      </div>
    </div>
		<nav class="mui-bar mui-bar-tab">
			<a id="defaultTab" class="mui-tab-item mui-active" data="./home/home.html">
				<span class="mui-icon ">
					<img src="img/home0.png" class="home_icon"/>
				</span>
				<span class="mui-tab-label">首页</span>
			</a>
			<a id="defaultTab1" class="mui-tab-item" data="./home/search.html">
				<span class="mui-icon ">
					<img src="img/home1_.png" class="home_icon"/>
				</span>
				<span class="mui-tab-label">搜索</span>
			</a>
			<a id="defaultTab2" class="mui-tab-item" data="./home/file.html">
				<span class="mui-icon ">
					<img src="img/home2_.png" class="home_icon"/>
					
				</span>
				<span class="mui-tab-label">设备档案</span>
			</a>
			<a id="defaultTab3" class="mui-tab-item" data="./home/work.html">
				<span class="mui-icon ">
					<img src="img/home3_.png" class="home_icon"/>
					
				</span>
				<span class="mui-tab-label">待办工作</span>
			</a>
			<a id="defaultTab4" class="mui-tab-item" data="./home/help.html">
				<span class="mui-icon">
					<img src="img/home4_.png" class="home_icon"/>
					
				</span>
				<span class="mui-tab-label">工作助手</span>
			</a>
		</nav>
		<script src="../../js/mui.min.js"></script>
		<script type="text/javascript" src="../../js/jquery-3.2.1.min.js"></script>
		<script type="text/javascript" src="../../js/vue.js"></script>
		<script src="./js/mkeyplus.base.js"></script>
		<script src="./js/sqlite.js"></script>
		<script type="text/javascript" charset="utf-8">
//		localStorage.clear();
			var first = null; //第一次点击backbutton
      var home = null;
			var network;
       var page;
			//mui初始化
			mui.init();
			mui.plusReady(function() {
				var clientInfo = plus.push.getClientInfo().clientid;
        modify(clientInfo);
       
			});
      home = new Vue({
        el: '#home',
        data: {
          editShow: false,
          checkModel: [],
          all: false
        },
        created: function() {
			localStorage.removeItem('parentId');
        },
        methods: {
          edit() {
            this.editShow = !this.editShow
            this.checkModel = []
          },
          checkChange() {
            var that = this;
            console.log(that.checkModel)
            var ids = []
            that.list.forEach(function(item, index) {
              ids.push(item.id);
            })
            if (that.checkModel.sort().toString() === ids.sort().toString()) {
              that.all = true
            } else {
              that.all = false
            }
          },
          chooseAll() {
            var that = this;
            // if (!that.all) {
            //   that.list.forEach(function(item, index) {
            //     that.checkModel.push(item.id);
            //   })
            // } else {
            //   that.checkModel = []
            // }
            that.all = !that.all;
             page = plus.webview.getWebviewById('./home/file.html');
            mui.fire(page, 'chooseAll', {
             all: that.all
            });   
          },
          offline(){
            console.log('离线缓存');
            var that=this;
            page = plus.webview.getWebviewById('./home/file.html');
            mui.fire(page, 'offline'); 
          },
          Delete() {
            var that = this;
            var btnArray = ['取消', '确定'];
            mui.confirm('确定删除吗？', '提示', btnArray, function(e) {
              if (e.index == 1) {
                that.checkModel.forEach((item, index1) => {
                  selectListSQL(bdName, "delete from offlineFiles WHERE mainId ='" + item + "'", function(data) {
                    select()
                  });
                })
              } else {
      
              }
            })
          }
        }
      })
      function modify(clientInfo){
        
         // updateInfo: (options) => http.put('/api/users/updateCurrentUserInfo',options),
         // this.$api.updateInfo({
         //     clientId: clientInfo
         // }).then(res => {}).catch(err => {
         
         // })
         //修改个推
         if(clientInfo){
           // alert('222222')
           mui.baseApp.httpRequst("/api/users/updateCurrentUserInfo", {
             clientId: clientInfo
           }, function(data) {
             console.log("修改个推成功");
           }, function() {
             plus.nativeUI.closeWaiting();
             console.log("获取数据失败");
           }, 'put')
         }
         
      }
			var subpages = ['./home/home.html', './home/search.html', './home/file.html', './home/work.html', './home/help.html'];

			var subpage_style = {
				top: '0px',
				bottom: '51px'
			};
			var aniShow = {};
			if(window.plus) {
				plusready();
			} else {
				document.addEventListener('plusready', plusready, false);
			}
			var activeTab;

			function plusready() {
				var self = plus.webview.currentWebview();
				network = self.network;
				for(var i = 0; i < 5; i++) {
					var temp = {};
					var sub = plus.webview.create(subpages[i], subpages[i], subpage_style,{network:network});
					console.log("窗口ID:" + sub.id);
					if(i != 0) {
						console.log("隐藏的窗口:" + sub.id);
						sub.hide();
					} else {
						temp[subpages[0]] = "true";
						mui.extend(aniShow, temp);
					}
					self.append(sub);
				}

				//默认当前激活选项 ，以及id

				activeTab = subpages[0];
				var defaultt = "./home/home.html";
				mui(".mui-bar-tab").on("tap", "a", function() {
					var targetTab = this.getAttribute('data');
					var defaultt = this.getAttribute("id");
					// console.log("当前点击按钮" + targetTab + defaultt);
					if(targetTab == activeTab) {
						return;
					}
					if(mui.os.ios || aniShow[targetTab]) {
						console.log("第二次打开了===" + targetTab);
						//					if(targetTab == "shouye1.html"){
						//						plus.webview.getWebviewById("shouye1.html").evalJS("refreshhome()");
						//					}
						plus.webview.show(targetTab, "fade-in", 0);
					} else {
						console.log("第一次打开了===");
						//否则，使用fade-in动画，且保存变量
						console.log("else===" + targetTab);
						//					if(targetTab == "shouye1.html"){
						//						plus.webview.getWebviewById("shouye1.html").evalJS("refreshhome()");
						//					}
						var temp = {};
						temp[targetTab] = "true";
						mui.extend(aniShow, temp);
						plus.webview.show(targetTab, "fade-in", 0);
					}

					console.log("隐藏的页面：" + activeTab);
					//隐藏当前;
					plus.webview.hide(activeTab);
					//plus.webview.show(targetTab);
					//更改当前活跃的选项卡
					activeTab = targetTab;
				});
			}
			//		mui.back = function(){			
			//			var main = plus.android.runtimeMainActivity();
			// 			main.moveTaskToBack(false);
			//		}
			mui(".mui-bar-tab a").each(function(i, btn) {
				btn.addEventListener('tap', function() {
					for(var j = 0; j < 5; j++) {
						var imgnum = j ;
						var imgstr = "img/home" + imgnum + "_.png";
						$(".home_icon").eq(j).attr("src", imgstr);
					}
					var thisimgnum = i;
					$(this).find(".home_icon").attr("src", "img/home" + thisimgnum + ".png");
					//bottom-icon2-.png
				}, false);
			});
      //自定义事件，模拟点击“首页选项卡”
      document.addEventListener('gohome', function() {
      	var defaultTab = document.getElementById("defaultTab1");
      	//模拟首页点击
        console.log(defaultTab)
      	mui.trigger(defaultTab, 'tap');
      	//切换选项卡高亮
      	var current = document.querySelector(".mui-bar-tab>.mui-tab-item.mui-active");
      	if (defaultTab !== current) {
      		current.classList.remove('mui-active');
      		defaultTab.classList.add('mui-active');
      	}
      });
			var old_back = mui.back;
			mui.back = function(){  
			    //显示上一个界面；  
			   var self = plus.webview.currentWebview();
			   var opener = self.opener(); 
			   old_back();  
			}
      
     // 监听返回
      document.addEventListener('back', function(event) {  
         old_back()
      });
      window.addEventListener("check", function(e) {
        home.editShow = !home.editShow;
      });
      window.addEventListener("checkAll", function(e) {
        home.all = e.detail.all;
      });

      window.addEventListener("homeOffline", function(e) {
        console.log('离线啊'+e.detail.idList)
        var idList = e.detail.idList;
        var list = e.detail.batchList;
        receive(idList,list);
      });
		</script>
	</body>

</html>